<!--#include file="../../../inc/AspCms_MainClass.asp" -->
<%
CheckAdmin("AspCms_Links.asp")

dim action : action=getForm("action", "get")
dim LinkType,LinkText,LinkDesc,ImageURL,LinkOrder,LinkStatus,LinkURL,ID,Linkgroup


Select case action
	case "del" : delLinks
	case "add" : addLinks
	case "edit" : editLinks
	case "on" : onOff "on", "Links", "LinkID", "LinkStatus", "", getPageName()
	case "off" : onOff "off", "Links", "LinkID", "LinkStatus", "", getPageName()
	case "ugroup" : updategroup	
	
End Select

Sub getContent
	ID = getForm("id","get")
	Dim rsObj 	: Set rsObj=Conn.Exec("select LinkType,LinkText,LinkDesc,ImageURL,LinkOrder,LinkStatus,LinkURL,Linkgroup from {prefix}Links where LinkID="&ID,"r1")
	if isnul(ID) then alertMsgAndGo "ID不能为空","-1"	
	LinkType=rsObj(0)
	LinkText=rsObj(1)
	LinkDesc=rsObj(2)
	ImageURL=rsObj(3)
	LinkOrder=rsObj(4)
	LinkStatus=rsObj(5)
	LinkURL=rsObj(6)
	Linkgroup=rsObj(7)
	rsObj.close	:	Set rsObj = nothing
End Sub

Sub editLinks
	ID=getForm("LinkID","post")
	LinkType=getForm("LinkType","post")	
	LinkText=getForm("LinkText","post")	
	LinkDesc=getForm("LinkDesc","post")	
	ImageURL =getForm("ImageURL","post")	
	LinkOrder=getForm("LinkOrder","post")
	LinkStatus=getCheck(getForm("LinkStatus","post"))
	LinkURL=getForm("LinkURL","post")	
	Linkgroup=getForm("Linkgroup","post")	
	
	if isnul(LinkText) then alertMsgAndGo "网站名称不能为空","-1"
	if isnul(LinkURL) then alertMsgAndGo "链接地址不能为空","-1"		
	if not isurl(LinkURL) then alertMsgAndGo "链接地址不正确","-1"	
	if isnul(LinkStatus) then LinkStatus=0
	conn.Exec "update {prefix}Links set LinkType="&LinkType&",LinkText='"&LinkText&"',LinkDesc='"&LinkDesc&"',ImageURL='"&ImageURL&"',LinkOrder="&LinkOrder&",LinkStatus="&LinkStatus&",LinkURL='"&LinkURL&"',Linkgroup="&Linkgroup&" where LinkID="&ID,"exe"
	
	alertMsgAndGo "修改成功","AspCms_Links.asp"
End Sub

Sub addLinks 	
	LinkType=getForm("LinkType","post")	
	LinkText=getForm("LinkText","post")	
	LinkDesc=getForm("LinkDesc","post")	
	ImageURL =getForm("ImageURL","post")	
	LinkOrder=getForm("LinkOrder","post")
	LinkStatus=getCheck(getForm("LinkStatus","post"))
	LinkURL=getForm("LinkURL","post")	
	Linkgroup=getForm("Linkgroup","post")	
	
	if isnul(LinkText) then alertMsgAndGo "网站名称不能为空","-1"
	if isnul(LinkURL) then alertMsgAndGo "链接地址不能为空","-1"		
	if not isurl(LinkURL) then alertMsgAndGo "链接地址不正确","-1"
	'if LinkType and isnul(ImageURL) then alertMsgAndGo "图片地址不能为空","-1"
	conn.Exec "insert into {prefix}Links(LinkType,LinkText,LinkDesc,ImageURL,LinkOrder,LinkStatus,LinkURL,Linkgroup) values('"&LinkType&"','"&LinkText&"','"&LinkDesc&"','"&ImageURL&"','"&LinkOrder&"','"&LinkStatus&"','"&LinkURL&"',"&Linkgroup&")","exe"		
	alertMsgAndGo "添加成功","AspCms_Links.asp"
End Sub	

Sub linksList
	Dim rsObj	:	Set rsObj=conn.Exec("select LinkID,LinkText,LinkURL,ImageURL,LinkOrder,LinkStatus,LinkType,Linkgroup from {prefix}Links Order by LinkOrder Asc,LinkID","r1")
	If rsObj.Eof Then 
		echo"<tr>"&vbcrlf& _
			"<td colspan='7'>没有数据</td>"&vbcrlf& _
		  "</tr>"&vbcrlf
	Else
		dim i
		i=0
		Do while not rsObj.Eof 
		Dim linkDisplay,linktype
		if rsObj(6) ="0" then linkDisplay=rsObj(1) : linktype ="文字链接"
		if rsObj(6) ="1" then linkDisplay="<img height=""30"" title="""&rsObj(1)&""" src="""&rsObj(3)&""">" : linktype ="图片链接"
		 echo"<tr>"&vbcrlf& _
			"<td class='input'><div class='label-box'><label for='Num"&rsObj(0)&"' class='uk-clearfix uk-float-left tm-transition'><span class='uk-float-left check check-select'><i class='tm-transition icon' uk-icon='icon: check'></i></span><input id='Num"&rsObj(0)&"' class='select' type='checkbox' value='"&rsObj(0)&"' name='id'></label></div></td>"&vbcrlf& _
			"<td>"&rsObj(0)&"</td>"&vbcrlf& _
			"<td>"&rsObj(1)&"</td>"&vbcrlf& _
			"<td>"&rsObj(2)&"</td>"&vbcrlf& _
			"<td>"&rsObj(4)&"</td>"&vbcrlf& _
			"<td>"&linktype&"</td>"&vbcrlf& _
			"<td class='edit'><input type='hidden' name='lid' value='"&rsObj(0)&"'><input class='uk-text-center' name='Linkgroup"&i&"' type='text' value='"&rsObj(7)&"'></td>"&vbcrlf& _
			"<td>"&getStr(rsObj(5),"<a href='?action=off&id="&rsObj(0)&"' title='启用'><i class='tm-transition icon state state-check' uk-icon='icon: check'></i></a>","<a href='?action=on&id="&rsObj(0)&"' title='禁用'><i class='tm-transition icon state state-close' uk-icon='icon: close'></i></a>")&"</td>"&vbcrlf& _
			"<td class='uk-flex uk-flex-center uk-text-center control'><ul class='uk-clearfix'><li class='uk-float-left'><a href='AspCms_LinksEdit.asp?id="&rsObj(0)&"'>修改</a></li><li class='uk-float-left'><a href='?action=del&id="&rsObj(0)&"' onClick='return confirm('确定要删除吗')'>删除</a></li></ul></td>"&vbcrlf& _
		  "</tr>"&vbcrlf
		  i=i+1
		  rsObj.MoveNext
		Loop
	End If
	rsObj.close	:	Set rsObj = nothing
End Sub

Sub delLinks 
	id=getForm("id","both")
	if isnul(id) then alertMsgAndGo "请选择要删除的内容","-1"

	conn.Exec "delete from {prefix}Links where LinkID in("&id&")" ,"exe"
'	alertMsgAndGo "删除成功","AspCms_Links.asp"	
	response.Redirect("AspCms_Links.asp")
End Sub 

Sub updategroup
	Dim ids				:	ids=split(getForm("lid","post"),",")
	Dim Linkgroups			
	If Ubound(ids)=-1 Then 	'防止有值为空时下标越界
		ReDim ids(0)
		ids(0)=""
	End If	
	
	Dim i
	
	For i=0 To Ubound(ids)
		Linkgroups=getForm("Linkgroup"&i,"post")		
		if isnum(trim(Linkgroups)) then
			Conn.Exec "update {prefix}links Set LinkGroup="&trim(Linkgroups)&" Where linkID="&trim(ids(i)),"exe"	
		else
			Conn.Exec "update {prefix}links Set LinkGroup=0 Where linkID="&trim(ids(i)),"exe"	
		end if
	Next
	
	
	alertMsgAndGo "更新组成功",getPageName()
End Sub

%>